﻿using System.Collections.Generic;
using System.Linq;
using MusicStore.Data.Repository;
using MusicStore.Entities;
using NUnit.Framework;

namespace MusicStore.Data.Test.Repository
{
	[TestFixture]
	public class TestDataGenerator : TestBase
	{
		private readonly AlbumRepository _repository = new AlbumRepository();

		/// <summary>
		/// create and save a series of albums used to leave some data on the database
		/// </summary>
		[Test, Explicit]
		public void SaveAlbums()
		{
			_repository.Session.BeginTransaction();
			List<Album> albums = FillWithSampleData();
			albums.ForEach(_repository.Save);
			_repository.Session.Transaction.Commit();

			// load albums
			int count = _repository.Albums().Count();
			Assert.That(count > 0);
			Album loaded = _repository.Albums().Where(a => a.Title.Contains("Title 1")).FirstOrDefault();
			Assert.IsNotNull(loaded);
			loaded = _repository.Albums().Where(a => a.Title == "NonExistant").FirstOrDefault();
			Assert.IsNull(loaded);

			// load some album summaries
			count = _repository.AlbumSummaries().Count();
			Assert.That(count > 0);
			AlbumSummary loaded2 = _repository.AlbumSummaries().Where(a => a.Title.Contains("Title 1")).FirstOrDefault();
			Assert.IsNotNull(loaded2);
			loaded2 = _repository.AlbumSummaries().Where(a => a.Title == "NonExistant").FirstOrDefault();
			Assert.IsNull(loaded2);
		}
	}
}
